﻿@model IList<NewLife.Cube.Entity.OAuthConfig>
@using NewLife;
@using NewLife.Cube
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using XCode.Membership
@{
    var fact = ViewBag.Factory as IEntityFactory;
    var page = ViewBag.Page as Pager;
    var set = ViewBag.PageSetting as PageSetting ?? PageSetting.Global;
    var ukey = fact.Unique;
}

<div class="card card-flush">
    <div class="card-body">
        <div class="table-responsive dataTables_wrapper dt-bootstrap4">
            <table class="table table-hover table-row-bordered table-row-dashed gy-4">
                <thead>
                    <tr class="fs-4 text-muted">
                        @if (set.EnableSelect && ukey != null)
                        {
                            <th class="text-center" style="width:10px;">
                                <div class="form-check form-check-sm form-check-custom form-check-solid">
                                    <input class="form-check-input" type="checkbox" id="chkAll" data-bs-toggle="tooltip" title="全选" />
                                </div>
                            </th>
                        }
                        <th><a href="@Html.Raw(page.GetSortUrl("Name"))">名称</a></th>
                        <th><a href="@Html.Raw(page.GetSortUrl("AppId"))">应用标识</a></th>
                        <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Scope"))">授权范围</a></th>
                        <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("AppUrl"))">应用地址</a></th>
                        <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Enable"))">启用</a></th>
                        <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Visible"))">可见</a></th>
                        <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("AutoRegister"))">自动注册</a></th>
                        @if (this.Has(PermissionFlags.Detail))
                        {
                            <th>操作</th>
                        }
                    </tr>
                </thead>
                <tbody>
                    @foreach (var entity in Model)
                    {
                        <tr>
                            @if (set.EnableSelect && ukey != null)
                            {
                                <td class="text-center align-middle pt-0 pb-0">
                                    <div class="form-check form-check-sm form-check-custom form-check-solid">
                                        <input class="form-check-input" type="checkbox" name="keys" value="@entity[ukey.Name]" />
                                    </div>
                                </td>
                            }
                            <td>
                                <span style="width:270px">
                                    <div class="d-flex align-items-center">
                                        @{
                                            var nickName = !entity.NickName.IsNullOrEmpty() ? entity.NickName : entity.Name;
                                            var url = "Sso/Login?name=" + entity.Name;
                                            url = "/" + url;
                                            var logo = !entity.Logo.IsNullOrEmpty() ? entity.Logo : ViewHelper.GetLogo(entity.Name);

                                            <div class="symbol symbol-40 symbol-sm flex-shrink-0">
                                                <div class="symbol-label">
                                                    @if (!logo.IsNullOrEmpty())
                                                    {
                                                        <img class="h-75 align-self-center" src="@logo" alt="photo">
                                                    }
                                                    else
                                                    {
                                                        <span class="symbol-label font-size-h5">@entity.Name.First()</span>
                                                    }
                                                </div>
                                            </div>
                                        }
                                        <div class="mx-2">
                                            <div class="text-dark-75 fs-4 fw-bolder mb-0">@entity.Name</div>
                                            <a class="text-muted text-hover-primary">@entity.NickName</a>
                                        </div>
                                    </div>
                                </span>
                            </td>
                            <td>
                                <span style="width:237px">
                                    <div class="fs-4 mb-0">@entity.AppId</div>
                                    <a class="text-muted text-hover-primary">@entity.Server</a>
                                </span>
                            </td>
                            <td class="align-middle">@entity.Scope</td>
                            <td class="align-middle">@entity.AppUrl</td>
                            <td class="text-center align-middle">
                                @{
                                    var bval = entity.Enable;
                                    @if (fact.Unique != null)
                                    {
                                        var key = entity[fact.Unique.Name];
                                        if (bval)
                                        {
                                            <a href="@Url.Action("SetEnable", null, new { id = key, enable = false })" data-action="action">
                                                <i class="fas fa-check fw-bolder" style="color: green;"></i>
                                            </a>
                                        }
                                        else
                                        {
                                            <a href="@Url.Action("SetEnable", null, new { id = key, enable = true })" data-action="action">
                                                <i class="fas fa-times fw-bolder" style="color: red;"></i>
                                            </a>
                                        }
                                    }
                                    else
                                    {
                                        if (bval)
                                        {
                                            <i class="fas fa-check fw-bolder" style="color: green;"></i>
                                        }
                                        else
                                        {
                                            <i class="fas fa-times fw-bolder" style="color: red;"></i>
                                        }
                                    }
                                }
                            </td>
                            <td class="text-center align-middle">
                                <i class="fas fa-@(entity.Visible ? "check" : "times") fw-bolder" style="color: @(entity.Visible ? "green" : "red");"></i>
                            </td>
                            <td class="text-center align-middle">
                                <i class="fa fa-@(entity.AutoRegister ? "check" : "times") fw-bolder" style="color: @(entity.AutoRegister ? "green" : "red");"></i>
                            </td>
                            @if (this.Has(PermissionFlags.Detail))
                            {
                                <td>
                                    @await Html.PartialAsync("_List_Data_Action", (Object)entity)
                                </td>
                            }
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>
